package com.tianqu.tms.www.finance.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferFinanceInfo;
import com.tianqu.tms.www.finance.viewhelper.FinanceSettlementSummaryViewHelper;

public class FinanceSettlementSummaryDetailController extends TmsController {
	private Logger logger = Logger.getLogger(FinanceSettlementSummaryDetailController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		try {
			String startDate = uc.getParameter("startDate");
			String endDate = uc.getParameter("endDate");
			String type = uc.getParameter("type");
			String pType = uc.getParameter("pType");
			
			FinanceSettlementSummaryViewHelper viewhelper  = new FinanceSettlementSummaryViewHelper();
			TransferFinanceInfo detail = TransferFinanceInfo.getInstance().findTransferFinanceDeail(startDate.replace("-", ""), endDate.replace("-", ""),Integer.parseInt(type),Integer.parseInt(pType));
			viewhelper.setDetails(detail.getDetailInfo());
			viewhelper.setStartDate(startDate);
			viewhelper.setEndDate(endDate);
			viewhelper.setType(type);
			viewhelper.setpType(pType);
			
			controller.commit();
			uc.setAttribute(TmsConstants.VIEWHELP, viewhelper);
		} catch (Exception e) {
			logger.error("",e);
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
}
